package com.service;

import com.entity.BusinessProjectRevenue;
import com.repository.BusinessProjectRevenueRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class BusinessProjectRevenueService {

    @Autowired
    private BusinessProjectRevenueRepository businessProjectRevenueRepository;

    /**
     * 保存项目营收信息
     * @param businessProjectRevenue 项目营收信息
     * @return 保存后的项目营收信息
     */
    public BusinessProjectRevenue save(BusinessProjectRevenue businessProjectRevenue) {
        return businessProjectRevenueRepository.save(businessProjectRevenue);
    }

    /**
     * 根据ID删除项目营收信息
     * @param id 项目营收ID
     */
    public void deleteById(Integer id) {
        businessProjectRevenueRepository.deleteById(id);
    }

    /**
     * 根据ID更新项目营收信息
     * @param businessProjectRevenue 项目营收信息
     * @return 更新后的项目营收信息
     */
    public BusinessProjectRevenue update(BusinessProjectRevenue businessProjectRevenue) {
        return businessProjectRevenueRepository.save(businessProjectRevenue);
    }

    /**
     * 根据ID查找项目营收信息
     * @param id 项目营收ID
     * @return 项目营收信息
     */
    public BusinessProjectRevenue findById(Integer id) {
        Optional<BusinessProjectRevenue> optional = businessProjectRevenueRepository.findById(id);
        return optional.orElse(null);
    }

    /**
     * 查找所有项目营收信息
     * @return 项目营收信息列表
     */
    public List<BusinessProjectRevenue> findAll() {
        return businessProjectRevenueRepository.findAll();
    }

    /**
     * 分页查询项目营收信息
     * @param pageable 分页参数
     * @return 项目营收信息分页结果
     */
    public Page<BusinessProjectRevenue> findAll(Pageable pageable) {
        return businessProjectRevenueRepository.findAll(pageable);
    }
}